// main.js
import { initTheme } from '@atom/b2c-tokens';
import '@atom/b2c-tokens/dist/variables_750_rem.css';
import filters from '@/scripts/filter.js';
import redGreen from '@/directives/redGreen.js';
import fontResize from '@/directives/fontResize.js';
import {
  Tab,
  Tabs,
  StockList,
  Tag,
  Popup,
  Overlay,
  Checkbox,
  CheckboxGroup,
  Cell,
  CalendarEntry,
  Calendar,
  Clamp,
  Empty,
  Tooltip,
  SearchInput,
  Sticky,
  NoticeBar,
  Switch,
  Toast,
  Button,
  Swipe,
  SwipeItem,
  Icon,
  Loading
} from '@atom/atom-ui';

initTheme({ darkMode: false });

export default Vue => {
  // 可以根据需求调整跨端控件的引入和注册

  const matrixComp = [
    window['thsc-mbweb-charge_permissionCard@1.0.2-beta.0'].default,
    window['thsc-mbweb-charge_helper@1.0.1'].default,
  ];
  const atomUi = [
    Tab,
    Tabs,
    StockList,
    Tag,
    Popup,
    Overlay,
    Checkbox,
    CheckboxGroup,
    Cell,
    CalendarEntry,
    Clamp,
    Calendar,
    Empty,
    Tooltip,
    SearchInput,
    Sticky,
    NoticeBar,
    Switch,
    Toast,
    Button,
    Swipe,
    SwipeItem,
    Icon,
    Loading
  ];

  [...atomUi, ...matrixComp].forEach(item => {
    Vue.use(item);
  });

  // 注册全局过滤器
  Object.keys(filters).forEach(key => Vue.filter(key, filters[key]));
  // 注册全局红涨绿跌
  Vue.use(redGreen);
  // 字体自动缩小
  Vue.use(fontResize);
  // 阻止启用生产信息
  Vue.config.productionTip = false;

  // 捕获全局异常记录到skywalking
  Vue.config.errorHandler = error => {
    window.ClientMonitor.reportFrameErrors(
      {
        // 类型
        category: 'js',
        // 级别
        grade: 'Warning',
      },
      error
    );
  };
};
